/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: GoldenInvalidSessionStrategy
 * Author:   zhouheng
 * Date:     2019/6/23 17:51
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.security.session;

import com.zhouh.golden.security.properties.GoldenSecurityProperties;
import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.security.web.session.InvalidSessionStrategy;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author zhouheng
 * @create 2019/6/23
 * @since 1.0.0
 */
public class GoldenInvalidSessionStrategy implements InvalidSessionStrategy  {

    private GoldenSecurityProperties goldenSecurityProperties;

    private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();

    @Override
    public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        redirectStrategy.sendRedirect(request, response, goldenSecurityProperties.getLogoutUrl());
    }

    public GoldenSecurityProperties getGoldenSecurityProperties() {
        return goldenSecurityProperties;
    }

    public void setGoldenSecurityProperties(GoldenSecurityProperties goldenSecurityProperties) {
        this.goldenSecurityProperties = goldenSecurityProperties;
    }
}